package com.tjakus.bean;

import java.util.List;

import com.tjakus.hibernate.HibernateUtil;
import com.tjakus.hibernate.Users;
import com.tjakus.logging.Logging;

public class UsersBean {

	private List<Users> usersList = HibernateUtil.getAllUsers();
	private String newEmail = "";
	private Users selectedUser = new Users();

	public Users getSelectedUser() {
		return selectedUser;
	}

	public void setSelectedUser(Users selectedUser) {
		Logging.getLogger().info("SET");
		Logging.getLogger().info("SET - ( " + selectedUser.getEmail() + " )");
		this.selectedUser = selectedUser;
	}

	public String getNewEmail() {
		return newEmail;
	}

	public void setNewEmail(String newEmail) {
		this.newEmail = newEmail;
	}

	public List<Users> getUsersList() {
		Logging.getLogger().info("GET USERS LIST");
		return usersList;
	}

	public void setUsersList(List<Users> usersList) {
		this.usersList = usersList;
	}

	public void add() {
		Logging.getLogger().info("ADD");
		if (newEmail != "") {
			Logging.getLogger().info("ADD - ( " + newEmail + " )");
			HibernateUtil.addUser(newEmail);
			this.setUsersList(HibernateUtil.getAllUsers());
			this.setNewEmail("");
		}
	}
	
	public void deleteUser() {
		Logging.getLogger().info("DELETE");
		Logging.getLogger().info("DELETE - ( " + selectedUser.getEmail() + " )");
		HibernateUtil.deleteUser(selectedUser.getEmail());
		usersList = HibernateUtil.getAllUsers();
	}
}
